source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif
endfunction


"{{ Windows 配置
set nocompatible
set guifont=Consolas:h11
" set renderoptions=type:directx
" ,level:0.50,\gamma:1.0,contrast:0.0,geom:1,renmode:5,taamode:1
"}}


" Vundle 的 filetype 有 Bug，需要先 filetype off
filetype off
"{{ 插件管理(安装vundle至bundle/vundle目录)
set runtimepath+=$VIMRUNTIME/bundle/vundle
call vundle#begin()
" required by lua.vim
Bundle 'kien/ctrlp.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'xolox/vim-misc'
Bundle 'xolox/vim-lua-ftplugin'
Bundle 'zeis/vim-kolor'
Bundle 'morhetz/gruvbox'
Bundle 'rust-lang/rust.vim'
Plugin 'racer-rust/vim-racer'
Plugin 'jremmen/vim-ripgrep'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
call vundle#end()
"}}


let g:mapleader = ","
set noundofile
set nobackup " 不产生临时文件
set nowritebackup
set noswapfile " 不产生交换文件
set tabstop=4
set softtabstop=4 " 编辑模式退格键回退长度4
set shiftwidth=4 " 缩进长度为4
set expandtab " 用空格缩进(noexpandtab则为tab缩进)
set nu " 显示行号
set autoindent " 开启自动缩进
set cindent	" 针对c语言自动缩进
set cursorline " 高亮当前行
colorscheme gruvbox " 设置配色方案
set encoding=utf-8 " 设置编码
set fileformat=unix
set fileencodings=utf-8,chinese,latin-1
set fencs=utf-8,gbk,ucs-bom,gb18030,gb2312,cp936 " 设置文件编码检测类型及支持格式
set langmenu=zh_CN.utf-8 " 指定菜单语言
language messages zh_CN.utf-8 " 解决consle输出乱码
filetype plugin indent on
syntax on
set cot=menu " 隐藏Scratch预览(去处preview)
set guioptions-=L
set guioptions-=r
set guioptions-=b

" Windows 使用 C-Y undo
unmap <C-Y>
" 使用 C-Tab 切换 tab
noremap <C-Tab> gt
" 使用内置 tab 样式而不是 gui
set guioptions-=e
" 不显示行尾、制表符等空白字符
set nolist
" 允许不保存切换 Buffer
set hidden
" 总是显示 statusline
set laststatus=2

" 粘贴来源设置为 0 号寄存器（只有复制的内容 y, x)
" x 剪切的内容放置到 0 号寄存器，可以供 p 使用
noremap p "0p
noremap x "0x

" 映射 QuickFix 窗口条目项的切换快捷键
noremap <A-n> :cn<CR>
noremap <A-p> :cp<CR>

" 设置输入法切换，拼音输入法模式也能进入插入模式了 GUI 模式下可用
set noimcmdline
set iminsert=2
set imsearch=2

" 底行保留5行
set scrolloff=5


" NERDTree
map <silent> <leader>fe :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&b:NERDTreeType == "primary") | q | endif


"{{ C-P
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_match_window = 'max:10,results:55'
" 使用 git 的筛选
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
" let g:ctrlp_user_command = 'dir %s* /-n /b /s /a-d'  " Windows
" let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-from=.ctrlpignored']
"}}


" 菜单配置
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"隐藏菜单栏和工具栏，按F2显示
set guioptions-=m
set guioptions-=T
map <silent> <F2> :if &guioptions =~# 'T' <Bar>
            \set guioptions-=T <Bar>
            \set guioptions-=m <Bar>
            \else <Bar>
            \set guioptions+=T <Bar>
            \set guioptions+=m <Bar>
            \endif<CR>


"{{ Rust 配置
" "C:\Program Files\Rust stable 1.0\bin
" let g:rustc_path = 'C:/Program Files/Rust beta 1.4/bin/rustc.exe'
" let g:racer_cmd = "D:/rust_proj/racer-master/target/release/racer.exe"
" let $RUST_SRC_PATH="D:/rust_proj/rust-1.3.0/src/"
" map <A-r> :RustRun <CR>
"}}


let g:airline_theme='serene'
let g:airline_solarized_bg='dark'